using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;

namespace AnguaRPGEngine.Library.Sockets
{
    /// <summary>
    /// used to notify the owner that connection has occurred
    /// </summary>
    public delegate void ConnectEventHandler();
    /// <summary>
    /// used to notify the owner that data has been received
    /// </summary>
    /// <param name="data">received data</param>
    /// <param name="numBytes">number of bytes received</param>
    public delegate void ReceiveEventHandler(byte[] data, long numBytes);
    /// <summary>
    /// used to notify that the connection timeout has occured
    /// </summary>
    public delegate void ConnectionTimeoutEventHandler();
    /// <summary>
    /// used to notify the owner that data has been sent
    /// </summary>
    /// <param name="sent">number of bytes sent</param>
    public delegate void SendEventHandler(int sent);
    /// <summary>
    /// used to notify the owner that client is closing
    /// </summary>
    public delegate void ClientClosingDelegate();
    /// <summary>
    /// used to notify the owner that a socket error has occurred
    /// </summary>
    /// <param name="sender">object (socket) raising the event</param>
    /// <param name="e">object that holds the exception information</param>
    public delegate void SocketErrorEventHandler(object sender, SocketException e);
    /// <summary>
    /// used to notify the owner that a general error has occurred
    /// </summary>
    /// <param name="sender">object (socket) raising the event</param>
    /// <param name="e">object that holds the exception information</param>
    public delegate void GeneralErrorEventHandler(object sender, Exception e);
    /// <summary>
    /// used to notify the owner that a new connection has been accepted
    /// </summary>
    /// <param name="cs">new accepted socket</param>
    public delegate void AcceptEventHandler(ClientSocket cs);

    #region StateObject Region
    /// <summary>
    /// Holds the state and buffer of socket during asynchronous callbacks
    /// </summary>
    public class StateObject
    {
        /// <summary>
        /// constructor; uses default bufferSize value of 10240
        /// </summary>
        public StateObject() : this(10240)
        {
        }

        /// <summary>
        /// constuctor; uses user-specified buffer size
        /// </summary>
        /// <param name="bufferSize"></param>
        public StateObject(int bufferSize)
        {
            BufferSize = bufferSize;
            Buffer = new byte[BufferSize];
        }

        /// <summary>
        /// the socket whose state object holds
        /// </summary>
        public Socket WorkSocket = null;	
        /// <summary>
        /// size of the receive buffer
        /// </summary>
        public int BufferSize = 10240;			
        /// <summary>
        /// the receive buffer
        /// </summary>
        public byte[] Buffer;	 
        /// <summary>
        /// the remote endpoint of the socket
        /// </summary>
        public IPEndPoint RemoteEP;
    }
    #endregion
}
